﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using movies;

public partial class movie : System.Web.UI.MasterPage
{
    public Customer current = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Customer"] != null)
        {
            Customer cs = (Customer)Session["Customer"];
            current = cs;
            this.setUpLoginMenu(cs.Name);
        }
       
    }

    /// <summary>
    /// Method checks to make sure the user is Valid
    /// </summary>
    /// <param name="user">emailid of the user</param>
    /// <param name="password">password</param>
    /// <returns>True if user is valid</returns>

    public bool isUserValid(string user, string password)
    {
        //invoke class for authentication
        LoginAuth userlogin = new LoginAuth();

        //check to see if the user is valid
        bool loginFlag = userlogin.isValidUser(user, password);

        if (loginFlag)
        {
            
            Customer cs = new Customer();
            cs = cs.getCustomer(user);
            Session["Customer"] = cs;
            
        }
        else
        {
            Session.Clear();
        }

        return loginFlag;

       
    }

    /// <summary>
    /// Sets up the top menu for a logged in user
    /// </summary>
    private void setUpLoginMenu(string name)
    {
            this.lblUser.Text = "Welcome " + name;
            this.lblUser.Visible = true;
            this.lnkMyAcc.Visible = true;
            this.lnkLogout.Visible = true;
            
    }
}
